﻿//using Kingdee.BOS.App.Core;
//using Kingdee.BOS.Core.DynamicForm.PlugIn;
//using Kingdee.BOS.Core.DynamicForm;
//using Kingdee.BOS.Core.List.PlugIn;
//using Kingdee.BOS.Core.List;
//using Kingdee.BOS.Core.ListFilter;
//using Kingdee.BOS.Core.Metadata;
//using Kingdee.BOS.Web.Core;
//using Kingdee.BOS.Web.DynamicForm;
//using Kingdee.BOS.Web.List;
//using Kingdee.BOS;
//using System;
//using Kingdee.BOS.Core;

//namespace LianKe.LianKeSchedule
//{
//    /// <summary>
//    /// 列表视图构建器
//    /// </summary>
//    public class ListViewBuilder
//    {
//        /// <summary>
//        /// 创建列表打印查询视图
//        /// </summary>
//        /// <param name="ctx"></param>
//        /// <param name="formId"></param>
//        /// <param name="schemeId"></param>
//        /// <returns></returns>
//        public IDynamicFormView CreateListPrintView(Context ctx, string formId, string schemeId)
//        {
//            // 构建报表窗体打开参数, 
//            var formMetaData = (FormMetadata)new MetaDataService().Load(ctx, formId);
//            // ShowParameter
//            var showParam = new ListShowParameter();
//            showParam.FormId = formId;
//            showParam.PageId = Guid.NewGuid().ToString();
//            var paraObj = showParam.CreateWebParams();
//            // OpenParameter
//            var dynamicFormMetaDataService = new DynamicFormMetaDataService();
//            var sessionManager = new SessionManager();
//            dynamicFormMetaDataService.SetContext(sessionManager, ctx);
//            dynamicFormMetaDataService.FormMetaData = formMetaData;
//            dynamicFormMetaDataService.GetDynamicFormConfig(paraObj);
//            var openParam = sessionManager.Get<DynamicFormOpenParameter>(showParam.PageId, FormConst.OPEN_PARAM);
//            openParam.SetCustomParameter("SessionManager", sessionManager);
//            // 创建视图
//            var rptView = new ListPrintWebService(schemeId, null, null);
//            // 初始化视图
//            var provider = GetListServiceProvider(openParam);
//            rptView.Initialize(openParam, provider);
//            rptView.LoadData();
//            return rptView;
//        }

//        /// <summary>
//        /// 获取报表服务提供者
//        /// </summary>
//        /// <returns></returns>
//        private IResourceServiceProvider GetListServiceProvider(DynamicFormOpenParameter param)
//        {
//            var provider = new FormServiceProvider();
//            provider.Add(typeof(IDynamicFormView), CreateListView(param));
//            provider.Add(typeof(DynamicFormViewPlugInProxy), new ListViewPlugInProxy());
//            provider.Add(typeof(DynamicFormModelPlugInProxy), new ListModelPlugInProxy());
//            provider.Add(typeof(IDynamicFormModelService), GetListModel(param));
//            provider.Add(typeof(IListFilterModelService), GetListFilterModel());
//            var type = TypesContainer.GetOrRegister("Kingdee.BOS.Business.DynamicForm.DefaultValue.DefaultValueCalculator,Kingdee.BOS.Business.DynamicForm");
//            provider.Add(typeof(IDefaultValueCalculator), Activator.CreateInstance(type));
//            // 注册IDBModelService
//            type = TypesContainer.GetOrRegister("Kingdee.BOS.Business.DynamicForm.DBModel.DBModelService,Kingdee.BOS.Business.DynamicForm");
//            provider.Add(typeof(IDBModelService), Activator.CreateInstance(type));
//            return provider;
//        }

//        /// <summary>
//        /// 获取视图
//        /// </summary>
//        /// <returns></returns>
//        private IDynamicFormView CreateListView(DynamicFormOpenParameter param)
//        {
//            var form = param.FormMetaData.BusinessInfo.GetForm();
//            if (form.FormGroups != null && form.FormGroups.Count > 0)
//            {
//                return new TreeListView();
//            }
//            else
//            {
//                return new ListView();
//            }
//        }

//        /// <summary>
//        /// 获取视图模型
//        /// </summary>
//        /// <returns></returns>
//        private IDynamicFormModelService GetListModel(DynamicFormOpenParameter param)
//        {
//            var form = param.FormMetaData.BusinessInfo.GetForm();
//            if (form.FormGroups != null && form.FormGroups.Count > 0)
//            {
//                var type = TypesContainer.GetOrRegister("Kingdee.BOS.Model.List.TreeListModel,Kingdee.BOS.Model");
//                return (IDynamicFormModelService)Activator.CreateInstance(type);
//            }
//            else
//            {
//                var type = TypesContainer.GetOrRegister("Kingdee.BOS.Model.List.ListModel,Kingdee.BOS.Model");
//                return (IDynamicFormModelService)Activator.CreateInstance(type);
//            }
//        }

//        /// <summary>
//        /// 创建过滤条件模型
//        /// </summary>
//        /// <returns></returns>
//        private IListFilterModelService GetListFilterModel()
//        {
//            var type = TypesContainer.GetOrRegister("Kingdee.BOS.Model.ListFilter.ListFilterModel,Kingdee.BOS.Model");
//            return (IListFilterModelService)Activator.CreateInstance(type);
//        }
//    }

//}